package ai.mspbots.test.entity;

import ai.mspbots.test.dto.ApiKeyDTO;
import ai.mspbots.test.handler.JsonNodeTypeHandler;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;

@TableName("sys_api_key")
@Data
public class ApiKeyEntity {
    
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    private Long tenantCode;
    
    private String apiKey;

    @TableField(typeHandler = JsonNodeTypeHandler.class)
    private JsonNode model;

    public static ApiKeyEntity covert(ApiKeyDTO apiKeyDTO) {
        ApiKeyEntity apiKeyEntity = new ApiKeyEntity();
        apiKeyEntity.setApiKey(apiKeyDTO.getApiKey());
        apiKeyEntity.setModel(null);
        apiKeyEntity.setTenantCode(apiKeyDTO.getTenantCode());
        return apiKeyEntity;
    }

    public static ApiKeyEntity covert(ApiKeyDTO apiKeyDTO, JsonNode modelName) {
        ApiKeyEntity apiKeyEntity = new ApiKeyEntity();
        apiKeyEntity.setApiKey(apiKeyDTO.getApiKey());
        apiKeyEntity.setModel(modelName);
        apiKeyEntity.setTenantCode(apiKeyDTO.getTenantCode());
        return apiKeyEntity;
    }
}
